package cn.billy.system.service.impl;

import cn.billy.org.domain.Department;
import cn.billy.system.domain.Menu;
import cn.billy.system.mapper.MenuMapper;
import cn.billy.system.service.IMenuService;
import cn.billy.basic.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author billy
 * @since 2022-07-11
 */
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu> implements IMenuService {

    @Autowired
    private MenuMapper menuMapper;


    @Override
    public List<Menu> menuTree() {
        List<Menu> menus = menuMapper.loadAll();
        List<Menu> mes = new ArrayList<>();
//        System.out.println("11111111111111======="+menus);
        for(Menu menu : menus){
            if (menu.getParentId() == null){
                mes.add(menu);
            } else {
                for (Menu child : menus){
                    if (child.getId() == menu.getParentId()){
                        child.getChildren().add(menu);
                        break;
                    }
                }
            }
        }

        return mes;
    }

}
